package com.chenyaowei.happyhub.controller;

import com.chenyaowei.happyhub.mapper.GoodsMapper.GoodVersionMapper;
import com.chenyaowei.happyhub.mapper.IndexNavMapper;
import com.chenyaowei.happyhub.pojo.GoodsPojo.GoodVersion;
import com.chenyaowei.happyhub.pojo.IndexNav;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminGoodVersionController {
    @Resource
    IndexNavMapper indexNavMapper;
    @Resource
    GoodVersionMapper goodVersionMapper;
    @RequestMapping("/toInsertGoodVersion")
    String toInsertGoodVersion(Model model,String goodId){
        List<IndexNav> indexNavList = indexNavMapper.selectAllType();
        model.addAttribute("goodId",goodId);
        model.addAttribute("indexNavList",indexNavList);
        return "insertGoodVersion";
    }
    @RequestMapping("/insertGoodVersion")
    String insertGoodVersion(Model model,String goodId,String goodVersionValue,String goodVersionPrice,String goodVersionCount){
        System.out.println(goodId+goodVersionValue+goodVersionPrice+goodVersionCount);
        List<IndexNav> indexNavList = indexNavMapper.selectAllType();
        goodVersionMapper.insertGoodVersion(goodId,goodVersionValue,goodVersionPrice,goodVersionCount);
        model.addAttribute("indexNavList", indexNavList);
        int ID = Integer.parseInt(goodId);
        List<GoodVersion> goodVersionList=goodVersionMapper.selectGoodVersionById(ID);
        model.addAttribute("goodVersionList",goodVersionList);
        model.addAttribute("goodId",goodId);
        return "goodVersion";
    }
    @RequestMapping("/updateGoodVersion")
    String updateGoodVersion(Model model,String versionId,String goodId,String goodVersionValue,String goodVersionPrice,String goodVersionCount){
        goodVersionMapper.updateVersion(versionId,goodVersionValue,goodVersionPrice,goodVersionCount);
        List<IndexNav> indexNavList = indexNavMapper.selectAllType();
        int ID = Integer.parseInt(goodId);
        List<GoodVersion> goodVersionList=goodVersionMapper.selectGoodVersionById(ID);
        model.addAttribute("indexNavList", indexNavList);
        model.addAttribute("goodVersionList",goodVersionList);
        model.addAttribute("goodId",goodId);
        return "goodVersion";
    }
    @RequestMapping("/deleteGoodVersion")
    String deleteGoodVersion(Model model,String versionId,String goodId){
        System.out.println(versionId+goodId);
        goodVersionMapper.deleteGoodVersion(versionId);
        List<IndexNav> indexNavList = indexNavMapper.selectAllType();
        int ID = Integer.parseInt(goodId);
        List<GoodVersion> goodVersionList=goodVersionMapper.selectGoodVersionById(ID);
        model.addAttribute("indexNavList", indexNavList);
        model.addAttribute("goodVersionList",goodVersionList);
        model.addAttribute("goodId",goodId);
        return "goodVersion";
    }


}
